//
//  SecondController.m
//  LittleSummary
//
//  Created by 郝旭珊 on 2018/1/4.
//  Copyright © 2018年 郝旭珊. All rights reserved.
//

#import "SecondController.h"
#import "BlockController.h"

@interface SecondController ()

@property (nonatomic, strong) UILabel *globalLabel;
@property (nonatomic, strong) UIButton *button;

@end

@implementation SecondController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 64, 100, 50)];
    button.backgroundColor = [UIColor greenColor];
    self.button = button;
    [self.view addSubview:button];
    
    self.globalLabel =  [[UILabel alloc]initWithFrame:CGRectMake(0, 200, 100, 50)];
    self.globalLabel.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.globalLabel];
    
}

- (void)callBlock{
    self.secondControllerBlockName(@"sencondText");
}


- (void)dealloc{
    NSLog(@"SecondController 走了");
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    BlockController *vc = [BlockController new];
    //EXC BAD ACCESS 如果没有执行 block, 会导致野指针错误, 先判断 block
    //block引用外部变量会自动做一次 copy 操作,
    vc.passText = ^(NSString *text) {
        NSLog(@"%@",text);
        [self.button setTitle:text forState:UIControlStateNormal];
    };
    
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
